﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using dzs.Model;
namespace dzs.BLL
{
	/// <summary>
	/// distribution
	/// </summary>
	public partial class distribution
	{
		private readonly dzs.DAL.distribution dal=new dzs.DAL.distribution();
		public distribution()
		{}
		#region  BasicMethod

        public int getuid(int did)
        {
            return dal.getuid(did);
        }
        public bool userList(string didlist, int uid)
        {
            return dal.userList(didlist, uid);
        }
        public bool userList(string didlist)
        {
            return dal.userList(didlist);
        }
        public bool Updatedatestatus(int ks, int js)
        {
            return dal.Updatedatestatus(ks, js);
        }
        public int addmaterial(int id)
        {
            if (!dal.Existsmaterial(id))
            {
                return dal.addmaterial(id);
            }
            else
                return 0;
        }
        public DataSet GetListdetailv(int did)
        {
            return dal.GetListdetailv(did);
        }
        public bool Updateaognum(int id, decimal num)
        {
            bool isok = false;
            isok = dal.Updateaognum(id,num);
            isok = isok && dal.Updatesta(id,1);

            return isok;
        }
        public bool delaognum(int id)
        {
            bool isok = false;
            isok = dal.delaognum(id);
            isok = isok && dal.delsta(id);
            return isok;
        }
        public bool Updatepinum(int id, decimal num)
        {
            bool isok = false;
            isok = dal.Updatepinum(id, num);
            isok = isok && dal.Updatesta(id, 2);
            return isok;
        }
        public bool delpinum(int id)
        {
            bool isok = false;
            isok = dal.delpinum(id);
            isok = isok && dal.Updatesta(id, 1);
            return isok;
        }
        public bool ConfirmList(string didlist, int sta)
        {
            return dal.ConfirmList(didlist, sta);
        }
        public DataSet GetListv(string strWhere)
        {
            return dal.GetListv(strWhere);
        }
        public bool Updatedis(dzs.Model.distribution model)
        {
            return dal.Updatedis(model);
        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int did)
		{
			return dal.Exists(did);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(dzs.Model.distribution model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(dzs.Model.distribution model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int did)
		{
			
			return dal.Delete(did);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string didlist )
		{
			return dal.DeleteList(didlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public dzs.Model.distribution GetModel(int did)
		{
			
			return dal.GetModel(did);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public dzs.Model.distribution GetModelByCache(int did)
		{
			
			string CacheKey = "distributionModel-" + did;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(did);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (dzs.Model.distribution)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<dzs.Model.distribution> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<dzs.Model.distribution> DataTableToList(DataTable dt)
		{
			List<dzs.Model.distribution> modelList = new List<dzs.Model.distribution>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				dzs.Model.distribution model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

